$(function(){
    // 滚动到底部
    $(".btn-goNext").on('click',function() {
        $('html, body').animate({scrollTop: $(document).height()}, 300);
    });

    // 手机号正确按钮可点击
    $("#phone").focusin(function(event) {
        if($(this).attr('placeholder') == '请输入手机号'){
            $(this).val('');
            $(this).attr('placeholder','');
        }
    });
    $("#phone").focusout(function(event) {
        if($(this).val() ==''){
            $(this).val('请输入手机号');
            $(this).attr('placeholder','请输入手机号');
        }

    });

    document.getElementById("phone").onkeyup = function() {
        var str = document.getElementById("phone").value
        var myreg=/^[1][3,4,5,6,7,8][0-9]{9}$/;
        if (myreg.test(str)) {
            $("#btn-sure").removeAttr('disabled').css('background','url(/static/index/images/img10.png) no-repeat');
        } else {
            $("#btn-sure").attr('disabled','disabled').css('background','url(/static/index/images/img11.png) no-repeat');
            return false;
        }
    }


    var float = false;
    // 立即预约按钮事件
    $("#btn-sure").on('click',function() {
        var phone = $('#phone').val();

        if(float == false) {
            float = true;
            layer.msg('预约中', {
                icon: 16
                ,shade: 0.01
            });
            $.ajax({
                url: '/index.php/index/index',
                data: {phone: phone},
                type: 'post',
                dataType: 'json',
                success: function (json) {
                    layer.closeAll();
                    if(json.code ==1){
                        $('#msg').css('display','none');
                        $('.pop').fadeIn('fast');
                    }else{
                        layer.msg(json.msg, {icon: 4});
                    }
                }
            })
        }

    });
});